package com.jkl.controller.user;

import com.jkl.entity.person.BsPerson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.jkl.entity.po.user.BSUser;
import com.jkl.service.user.inter.BSUserServiceInterface;
import com.jkl.untils.MD5Util;

import lombok.extern.slf4j.Slf4j;

import java.util.List;

@RestController
@RequestMapping("/jky/user")
@Slf4j
public class BSUserControllerV1 {

	@Autowired
	private BSUserServiceInterface bsUserServiceInterface;

	@PostMapping("/getAllUserByParam")
	public PageInfo<BSUser> getAllUserByParam(@RequestBody BSUser params) throws Exception {
		PageInfo<BSUser> allUserByParam = bsUserServiceInterface.getAllUserByParam(params);
		return allUserByParam;
	}

	@PostMapping("/updateUser")
	public boolean updateUser(@RequestBody BSUser bsUser) throws Exception {
		bsUser.setPassword(MD5Util.toMD5(bsUser.getPassword()));
		bsUserServiceInterface.updateUser(bsUser);
		return true;
	}

	@PostMapping("/addUser")
	public boolean addUser(@RequestBody BSUser bsUser) throws Exception {
		bsUser.setPassword(MD5Util.toMD5("123456"));
		bsUserServiceInterface.addUser(bsUser);
		return true;
	}

	@PostMapping("/addUserRole")
	public boolean addUserRole(@RequestBody BSUser bsUser) throws Exception {
		return bsUserServiceInterface.addUserRole(bsUser);
	}

	@PostMapping("/addUserWithPersonId")
	public boolean addUserWithPersonId(@RequestBody BSUser bsUser) throws Exception {
		return bsUserServiceInterface.addUserWithPersonId(bsUser.getRowId(),bsUser.getPersonId());
	}
}
